import {observable,action} from '../miniprogram_npm/mobx-miniprogram/index'
const app = getApp()
export const store = observable({
  // 数据字段
  numA:5,
  numB:2,
  activeTabBarIndex:0,
  // 计算属性
  get sum(){
    return this.numA 
  },
  // actions 函数，专门来修改 store 中数据的值
  getUnRead:action(function(){
        var that = this;
        wx.request({
            url: app.getUrl('/xcx/pt/userNoReadMessage'),
            method: 'GET',
            header: wx.getStorageSync('cookie'),
            success(res) {
                let messageList = res.data.data;
                if (messageList) {
                        wx.showTabBarRedDot({
                            index: 1,
                            success(res) {
                                console.log(res)
                            }
                        })
                        that.numA = messageList.length
                } else {
                    wx.hideTabBarRedDot({
                        index: 1,
                        success(res) {
                            console.log(res)
                        }
                    })
                    that.numA= 0
                    
                }
            }
        })
    
  }),
  updateNum2:action(function(step){
    this.numB += step
  }),
  updateActiveTabBarIndex:action(function(index){
    this.activeTabBarIndex = index
  })
})